/*globals $ OpenLayers jsper*/
$.extend({
    loadMapState: function(mapObj, geojsonObjects) {
        try {
            var featureTypes = ["Point", "LineString", "Polygon"], geoJSONParser = new OpenLayers.Format.GeoJSON();
            
            $.each(['LineString', 'Point', 'Polygon'], function(i, featureType) {
                $.each(geojsonObjects[featureType].features, function(i, polyData) {
                    //assume closed geometry, so vist every point
                    var geometry;
                    geometry = geoJSONParser.parseGeometry(polyData.geometry);
                    //store the properties from the geoJSON file inside the
                    //OpenLayers geometry object, this is used later on hover events
                    //to print out a div with those properties
                    geometry.properties = polyData.properties;
                    
                    //Transform coordinates from lat/lng into the map's projection
                    geometry.transform(mapObj.proj, mapObj.map.getProjectionObject());
                    if (geometry.properties['Feature-Type']) {
                        if (geometry.properties['Feature-Type'] === 'Future') {
                            mapObj.futureLayer.addFeatures([new OpenLayers.Feature.Vector(geometry, null, null)]);
                        } else {
                            mapObj.existingLayer.addFeatures([new OpenLayers.Feature.Vector(geometry, null, null)]);
                        }
                    } else {
                        mapObj.defaultLayer.addFeatures([new OpenLayers.Feature.Vector(geometry, null, null)]);
                    }
                });
            });
        } 
        catch (e) {
            //means no geojson stored, or something else broke, just clear and login
            jsper.clear();
            $.login();
        }
    }
});
